import {MENU} from '@/services/api'
import {request, METHOD} from '@/utils/request'

/**
 *
 * @param pageQuery
 * @returns Promise<AxiosResponse>
 */
export async function page(pageQuery) {
    return request(MENU.MENU_PAGE, METHOD.POST, {
        ...pageQuery
    })
}

/**
 *
 * @returns  Promise<AxiosResponse>
 */
export async function list() {
    return request(MENU.MENU_LIST, METHOD.POST, {})
}

/**
 *
 * @returns  Promise<AxiosResponse>
 */
export async function menuTree() {
    return request(MENU.MENU_TREE, METHOD.GET, {})
}


/**
 *
 * @param id
 * @returns Promise<AxiosResponse>
 */
export async function del(id) {
    return request(MENU.MENU_DELETE + `/${id}`, METHOD.POST, {})
}

/**
 *
 * @param id
 * @returns Promise<AxiosResponse>
 */
export async function underlings(id) {
    return request(MENU.MENU_UNDERLINGS + `/${id}`, METHOD.GET, {})
}

/**
 *
 * @param menu
 * @returns Promise<AxiosResponse>
 */
export async function save(menu) {
    return request(MENU.MENU_ADD_OR_UPDATE, METHOD.POST, {
        ...menu,
    })
}

export const columns = [
    {
        title: '菜单名称',
        dataIndex: 'name',
        align: 'center',
    },
    {
        title: '菜单类型',
        dataIndex: 'mode',
        align: 'center',
        scopedSlots: {customRender: 'modeIndex'}
    },
    {
        title: '菜单路由',
        dataIndex: 'router',
        align: 'center',
    },
    {
        title: '权限编码',
        dataIndex: 'authority',
        align: 'center',
    },
    {
        title: '菜单序列',
        dataIndex: 'sort',
        align: 'center',
    },
    {
        title: '图标',
        dataIndex: 'icon',
        align: 'center',
        scopedSlots: {customRender: 'iconIndex'}
    },
    {
        title: '操作',
        align: 'center',
        scopedSlots: {customRender: 'action'}
    }
]
